package com.example.service.impl;

import com.example.entity.Shoucang;
import com.example.mapper.ShangpinMapper;
import com.example.service.IShangpinService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShangpinServiceImpl implements IShangpinService {

    @Autowired
    private ShangpinMapper shangpinMapper;

    @Override
    public PageInfo<Shoucang> findAll(String name, Integer typeId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        List<Shoucang> list = shangpinMapper.findAll(name,typeId);

        PageInfo<Shoucang> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }

    @Override
    public void delete(Integer id) {
        shangpinMapper.delete(id);
    }

    @Override
    public Shoucang getById(Integer id) {
        return shangpinMapper.getById(id);
    }

    @Override
    public void update(Shoucang shoucang) {
        shangpinMapper.update(shoucang);
    }

    @Override
    public Shoucang findOneByProductId(Integer  goodsId) {
        return shangpinMapper.findOneByProductId( goodsId);
    }
}
